import {findPage} from "@/api/goods/goods";
import {add, addArray, findGoodById, GetdataDictionary} from "@/api/b2c/order";

export default {
    name: "addOrder",
    data() {
        return {
            tableData: [],
            imageUrl: '',//图片路径
            brandList: {},//品牌集合
            typeList: {},//类型集合
            colourList: {},//颜色集合
            num: 1,
            searchParams: {currentPage: 1, pageSize: 5, brandId: "", typeId: "", colourId: ""},//商品查询条件
            total: 0,
            //添加订单
            dialogFormVisible: false,
            formData: {},//添加的集合
            receiverInfo: [],
            goodList: [],
            isDisabled: false,
            //添加商品
            orderGoods: [],
            goodArray: [],
            idList: {},
            goodInfo: {
                brandId: ``,
                colourId: ``,
                id: ``,
                goodsName: ``,
                typeId: ``,
                modelId: ``,
                goodPrice: ``,
                goodNumber: ``,
                goodMoney: ``
                // goodNumber:``,
                // goodMoney:``
            },
        }
    },
    methods: {
        //购买数量加减
        handleChange(value) {
            console.log(value);
        },

        //查询所有商品
        async searchPage() {
            let response = await findPage(this.searchParams);
            this.tableData = response.data;
            this.total = response.total;
        },

        //页面变化
        currentPageChange(currentIndex) {
            this.searchParams.currentPage = currentIndex;
            this.searchPage();
        },
        //数据字典
        async querydic() {
            //1.订单动作 2 订单状态 3 业务类型 4 配送方式  5 支付方式  6订单分类订单类型 7 退货原因 ',
            let result = await GetdataDictionary();
            console.log(result)
            this.orderActionlist = result[1]
            this.orderStatusList = result[2]
            this.businessTypeList = result[3]
            this.payTypeList = result[5]
            this.orderTypeList = result[6]
            // console.log(this.orderTypeList)
        },
        //================================
        //选择该行数据
        handleSelectionChange(val) {
            this.multipleSelection = val;
          //  console.log(this.multipleSelection)
            this.goodArray=val;

            // console.log(this.goodArray)
        },
        //批量添加
        async addBatch() {
            console.log(this.goodArray)
            await addArray(this.goodArray).then(response=>{
                if (response === 1){
                    this.open()
                    this.searchPage()
                }
            })
        },

        async addGood(row) {
            this.goodInfo.brandId = row.brandId;
            this.goodInfo.goodsName = row.goodsName;
            this.goodInfo.goodNumber = 1;
            this.goodInfo.goodPrice = row.goodPrice;
            this.goodInfo.goodMoney = this.goodInfo.goodNumber * this.goodInfo.goodPrice
            this.goodInfo.modelId = row.modelId;
            this.goodInfo.id = row.id;
            this.goodInfo.colourId = row.colourId;
            this.goodInfo.typeId = row.typeId;
            console.log(this.goodInfo);
            let response = await add(this.goodInfo)
            if (response === 1) {
                this.open()
                // this.isDisabled = true;
            }
        },
        //查看购物车
        lookShoppingCart() {
            location.href = "/order/shopping"
        },
        //根据商品id查询
        async findOrderById(row) {
            await findGoodById(row.id)
        },
        open() {
            this.$message('商品已添加');
        },
        back(){
            location.href="/order/order"
        }


    },
    created() {
        this.searchPage()
        this.querydic()
    }
}